<?php

namespace app\api\controller;

use app\admin\model\AffiliatedCenter;
use app\common\controller\Api;
use fast\Tree;
use think\Loader;
use think\Validate;

/**
 * 首页接口
 */
class Communal extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @MethodName 獲取系統文章
     * @Author     Allen
     * @DateTime   2021-10-03T16:41:08+0800
     * @return     [array]
     */
    public function getSystemArticle()
    {
        $rq_data  = $this->request->param();
        $validate = Loader::validate('SystemArticle');
        if (!$validate->scene('info')->check($rq_data)) {
            $this->error($validate->getError());
        }

        $model = new \app\admin\model\SystemArticle;
        $info  = $model->field('id,content,createtime')->where(['id' => $rq_data['id']])->find();
        $model->where(['id' => $rq_data['id']])->setInc('click');
        $this->success('請求成功', $info);
    }

    /**
     * [getAllArea 獲取全部地區]
     * @MethodName
     * @Author     Allen
     * @DateTime   2021-10-25T15:04:46+0800
     * @param      string                   $value [description]
     * @return     [type]                          [description]
     */
    public function getAllArea($value = '')
    {
        $list = db('area')->field('id,pid,name')->where(['deletetime' => null])->order('weigh DESC,id ASC')->select();
        $Tree = new Tree;
        $Tree->instance()->init($list, null, '');
        $list = Tree::instance()->getTreeArray(0);
        $this->success('請求成功', $list);
    }

    /**
     * [getAffiliatedCenterList 獲取中心列表]
     * @MethodName
     * @Author     Allen
     * @DateTime   2022-07-21T01:35:51+0800
     * @return     [type]                   [description]
     */
    public function getAffiliatedCenterList()
    {
        $model = new AffiliatedCenter;

        $list = $model
            ->field('id,name')
            ->order('id desc')
            ->select();

        $this->success('請求成功', $list);
    }
}
